package com.fruit.web.vo.genl;

import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import com.fruit.service.IPeriodReceiveTimeService;
import com.fruit.utils.MessageFactory;
import com.fruit.utils.SpringFacesUtil;
import com.fruit.web.bo.impl.PeriodReceiveTime;
import com.fruit.web.constant.EjdConstants;
import com.fruit.web.constant.SpringBeanConstants;

@ManagedBean(name="existPeriodReceiveTime")
@SessionScoped
public class ExistPeriodReceiveTimeBean implements java.io.Serializable {

	private List<PeriodReceiveTime> periods = new ArrayList<PeriodReceiveTime>();

	public List<PeriodReceiveTime> getPeriods() {
		return periods;
	}

	public void setPeriods(List<PeriodReceiveTime> periods) {
		this.periods = periods;
	}

	public ExistPeriodReceiveTimeBean() {
		
		IPeriodReceiveTimeService<PeriodReceiveTime,Long> periodReceiveTimeService = (IPeriodReceiveTimeService<PeriodReceiveTime,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.PERIOD_RECEIVE_TIME_SERVICE_BEAN_NAME);
		periodReceiveTimeService.setEntityClass(PeriodReceiveTime.class);
		periodReceiveTimeService.setPKClass(Long.class);
		List<PeriodReceiveTime> periodReceiveTimes = periodReceiveTimeService.getAll();
		if (null != periodReceiveTimes && !(periodReceiveTimes.isEmpty())) {
			for (int i=0; i< periodReceiveTimes.size(); i++) {
				PeriodReceiveTime periodReceiveTime = (PeriodReceiveTime) periodReceiveTimes.get(i);
				String periodReceiveTimesDescN18 = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME,periodReceiveTime.getPeriodName(), FacesMessage.SEVERITY_ERROR).getDetail();
				periodReceiveTime.setPeriodDesc(periodReceiveTimesDescN18);
			}
		}
		this.setPeriods(periodReceiveTimes);
	}
}
